package org.smr.ministore.micro.client;

import java.util.List;

import org.blade.utils.Pager;
import org.smr.ministore.entities.Authority;
import org.smr.ministore.entities.Role;
import org.smr.ministore.entities.User;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value="User.Service",/*fallback = HystrixClientFallback.class, */fallbackFactory = HystrixUserClientFactory.class)
public interface FeignUserMicroServiceClient {

    @RequestMapping(method = RequestMethod.POST, value = "/User/batchSave")
    int batchSave(@RequestBody List< User> entities);

    @RequestMapping(method = RequestMethod.PUT, value = "/User/save")
    public int save(@RequestBody User entity) ;

    @RequestMapping(method = RequestMethod.PATCH, value = "/User/updateById")
    public int updateById(@RequestBody User id);

    @RequestMapping(method = RequestMethod.GET, value = "/User/queryById/{id}")
    public  User queryById(@PathVariable("id")Long id);

    @RequestMapping(method = RequestMethod.DELETE, value = "/User/deleteById/{id}")
    public int deleteById(@PathVariable("id")Long id);

    @RequestMapping(method = RequestMethod.POST, value = "/User/paginate/{pageSize}/{pageNum}")
    public Pager<User> paginate( @RequestBody User entity,  @PathVariable("pageSize")Long pageSize,  @PathVariable("pageNum")Long pageNum );

    /**
     * 根据用户名查询
     * @param userName
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/User/queryByUserName/{userName}")
    public User queryByUserName( @PathVariable("userName") String userName );

    /**
     * 根据用户名查询用户数
     * @param userName
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/User/getCountByUserName/{userName}")
    public Long getCountByUserName(  @PathVariable("userName") String userName );


    /**
     * 根据用户Id查询角色
     * @param userId
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/User/getRoleByUser/{userId}")
    List<Role> getRoleByUser( @PathVariable("userId") Long userId );


    /**
     * 根据用户Id查询权限
     * @param userId
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/User/getAuthoritiesByUser/{userId}")
    List<Authority> getAuthoritiesByUser(@PathVariable("userId") Long userId );

}
